﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Session["user_login"] != null)//如果用户登录
        {
            int a = (int)Session["user_status"];
          
            if (a== 0)
            {//登录成功隐藏Panel1，Panel3，显示Panel2            
                Panel1.Visible = false;
                Panel2.Visible = true;
                Panel3.Visible = false;
            }
            else
            {//登录成功且具有管理员权限隐藏Panel1，显示Panel2，Panel3   
                Panel1.Visible = false;
                Panel2.Visible = true;
                Panel3.Visible = true;
            }
        }
        else         //如果用户隐藏登录
        {       
                 // 显示Panel1，隐藏Panel2, Panel3
            Panel1.Visible = true;
             Panel2.Visible = false;
             Panel3.Visible = false;
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        user user = new user();
        if (user.login(userLogin.Text, userPwd.Text))
        {
            //设置Session;
            Session["user_login"] = userLogin.Text;
            Session["user_id"] = user.id;
            Session["user_name"] = user.name;
            Session["user_status"] = user.status;
            System.Diagnostics.Debug.Write(user.status);
            Session["user_idcard"] = user.idcard;
            Session["user"] = user;
            Panel2.Visible = false;
            Panel1.Visible = false;
            Panel3.Visible = false;
            Response.Redirect(Request.Path + "?" + Request.QueryString);
            Response.Write("<script>alert('登录成功')</script>");
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "warning", "alert(\"" + user.errorMsg + "\");", true);
        }
    }

    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.AddHeader("Refresh", "0");
    }
}

